package com.itheima.chapter09.io.charstream;

import java.io.*;

//字符缓冲流
public class BufferedStreamDemo1 {
    public static void main(String[] args) throws IOException {
        //写数据
        BufferedWriter bw =new BufferedWriter(new FileWriter("MyIdeaTest\\e.txt"));
        bw.write(97);
        bw.write(98);
       // bw.write("\r\n");
        bw.newLine();
        //行分隔符BufferedWriter特有
        char[] chars ={97,98,99,100};
        bw.write(chars);
        bw.newLine();
        //bw.write("\r\n");
        bw.write(chars,0,3);
        //bw.write("\r\n");
        bw.newLine();
        String s = "我爱中国";
        bw.write(s);
        //bw.write("\r\n");
        bw.newLine();
        bw.write(s,1,2);
        bw.flush();
        bw.close();

        BufferedReader br =new BufferedReader(new FileReader("MyIdeaTest\\e.txt"));
        //一次读一个数据
       /* int ch;
        while((ch=br.read())!=-1){
            System.out.println((char)ch);
        }
        System.out.println("======================");*/
        //一次读多个数据
        /*char[] chars =new char[1024];
        int len;
        while((len=br.read(chars))!=-1){
            System.out.println(new String(chars,0,len));
        }*/
        //readLine读一行文字
        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }
        br.close();

    }
}
